package com.quectel.business.common.websocket;

import com.quectel.business.common.websocket.send.SendMsg;
import com.quectel.constant.WebSocketConstants;
import com.quectel.sys.module.sys.service.SysConfigService;
import com.quectel.util.common.JacksonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * websocket发送
 *
 * @author: caolu
 * @email: louis.cao@quectel.com
 * @date: 2023-05-18 17:07:00
 */
@Component
@Slf4j
public class WebSocketComponent {

    @DubboReference
    private SysConfigService sysConfigService;
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /** 向CMS发送消息
     * @param villageId
     * @param msgType
     * @param title
     * @param content
     * @param extParams
     * @see com.quectel.business.common.websocket.send.SendMsgType
     */
    public void sendMsgToCmsApi(Long villageId, String msgType,String title, String content, Map<String, Object> extParams) {
        stringRedisTemplate.convertAndSend(WebSocketConstants.CmsApi.MSG_SEND_TOPIC,
                JacksonUtils.toJsonString(new SendMsg(villageId, msgType, title, content, extParams)));
    }

}
